// compile: g++ -o test test.cc -std=c++14
// run: ./test
#include <iostream>
#include <memory>

#include "shared_ptr.h"
using namespace std;

class XXX {
 public:
  XXX() { cout << "XXX construct, addr:" << this << endl; }
  ~XXX() { cout << "XXX deconstruct, addr:" << this << endl; }

 private:
};
void Test1() {
  unique_ptr<XXX> up1(std::make_unique<XXX>());
  cout << "sizeof up1 = " << sizeof up1 << endl;  // 8
}
void Test2() {
  shared_ptr<XXX> sp1(std::make_shared<XXX>());
  cout << "sizeof sp1 = " << sizeof sp1 << endl;  // 16
  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  shared_ptr<XXX> sp2(sp1);
  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  cout << "sp2.use_count() = " << sp2.use_count() << endl;
  XXX* tmp = sp1.get();
  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  cout << "sp2.use_count() = " << sp2.use_count() << endl;
  sp1.reset();
  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  cout << "sp2.use_count() = " << sp2.use_count() << endl;

  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  cout << "sp2.use_count() = " << sp2.use_count() << endl;
}
void Test3() {
  using namespace lei;
  lei::shared_ptr<XXX> sp1(new XXX);
  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  lei::shared_ptr<XXX> sp2(sp1);
  cout << "sp1.use_count() = " << sp1.use_count() << endl;
  cout << "sp2.use_count() = " << sp2.use_count() << endl;
}
void Test4() { unique_ptr<XXX> up1; }
int main() {
  // Test1();
  // Test2();
  Test3();
  return 0;
}
